package com.example.mq.consumer.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SpringRabbitListener {
	@RabbitListener(bindings = @QueueBinding(
			value = @Queue(name = "direct.queue1"),
			exchange = @Exchange(name = "spring.direct",type = ExchangeTypes.DIRECT),
			key = {"red","blue"}
	))
	public  void  listenDirectQueue1(String message){
		System.out.println("消费者接收到 direct.queue1的消息：【"+message+"】");
	}


	@RabbitListener(bindings = @QueueBinding(
			value = @Queue(name = "direct.queue2"),
			exchange = @Exchange(name = "spring.direct",type = ExchangeTypes.DIRECT),
			key = {"red","yellow"}
	))
	public  void  listenDirectQueue2(String message){
		System.out.println("消费者接收到 direct.queue2的消息：【"+message+"】");
	}



	@RabbitListener(bindings = @QueueBinding(
			value = @Queue(name = "topic.queue1"),
			exchange = @Exchange(name = "spring.topic",type = ExchangeTypes.TOPIC),
			key = {"spring.#"}
	))
	public  void  listenTopicQueue1(String message){
		System.out.println("消费者接收到 topic.queue1的消息：【"+message+"】");
	}


	@RabbitListener(bindings = @QueueBinding(
			value = @Queue(name = "topic.queue2"),
			exchange = @Exchange(name = "spring.topic",type = ExchangeTypes.TOPIC),
			key = {"#.news"}
	))
	public  void  listenTopicQueue2(String message){
		System.out.println("消费者接收到 topic.queue2的消息：【"+message+"】");
	}


	@RabbitListener(queues = "object.queue")
	public void listenObjectQueue(Map<String,Object> msg){
		System.out.println("接收到object.queue的消息：【"+msg+"】");
	}


}
